import grails.util.GrailsUtil
import tvdi.Usuario
import tvdi.Curso
import tvdi.Modulo
import tvdi.Aluno

class BootStrap {

    def init = { servletContext ->
		switch(GrailsUtil.environment){
			case "development":
				
				def admin = new Usuario(
					login:"admin",
					password:"123",
					role:"admin"
				)
				admin.save()
				if(admin.hasErrors()){
					println admin.errors
				}
				
				def rafael = new Usuario(
					login:"rafael",
					password:"123456",
					role:"user"
				)
				rafael.save()
				if (rafael.hasErrors()){
					println rafael.errors
				}
								
				def tvdi = new Curso(
					nome:"TV Digital", 
					dataInicio:(new Date () -30),
					dataFim: (new Date () +270),
				)
				tvdi.save()
				if(tvdi.hasErrors()){
					println tvdi.errors
				}
				
				def informatica = new Modulo(
					nome: "Informática",
					dataInicio:(new Date () +10),
					dataFim: (new Date () +70),
					maximoAlunos: 30,
					cargaHoraria: 30,
					curso:tvdi
				)
				informatica.save()
				if (informatica.hasErrors()){
					println informatica.errors
				}
				
				def aluno_rafael = new Aluno (
					nome: "Rafael Gomes de Oliveira",
					nascimento: (new Date () -724890),
					email: "rafaell.gomes@gmail.com",
					endereco: "Rua das Águias, 7988. Cidade Satélite",
					cidade: "Natal",
					estado: "RN",
					cep: "59067430",
					telefone: "88888888",
					celular: "99999999",
					modulo:informatica
				)
				
				aluno_rafael.save()
				if (aluno_rafael.hasErrors()){
					println aluno_rafael.errors
				}

				break
				
				case "production" :
					def admin = new Usuario(
					login:"admin",
					password:"Lum3nU3RN",
					role:"admin"
					)
					admin.save()
					if(admin.hasErrors()){
						println admin.errors
					}
				break
		}
    
    }
    def destroy = {
    }
}
